/*
 * @Author: fengshan0525 2735332396@qq.com
 * @Date: 2023-03-17 20:42:43
 * @LastEditors: fengshan0525 2735332396@qq.com
 * @LastEditTime: 2023-05-25 19:52:07
 * @FilePath: \nest-template\libs\db\src\models\user.model.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ApiProperty } from '@nestjs/swagger';
import { modelOptions, prop } from '@typegoose/typegoose';
import { UserFields } from 'types/modelFields';
import { IsNotEmpty, IsOptional, Allow } from 'class-validator';

@modelOptions({
  // 自动为每个属性添加时间戳
  schemaOptions: {
    timestamps: true,
  },
})
export class AdminUsers implements UserFields {
  @ApiProperty({ description: '用户昵称' })
  @IsOptional()
  @prop()
  nickName: string;

  @ApiProperty({ description: '用户名称(登录时使用)', required: true })
  @IsNotEmpty({ message: '用户名称不能为空' })
  @prop()
  username: string;

  @ApiProperty({ description: '密码', required: true })
  @IsNotEmpty({ message: '密码不能为空' })
  @prop()
  password: string;

  @ApiProperty({ description: '手机号' })
  @IsOptional()
  @prop()
  telephone: string;

  @ApiProperty({ description: '邮箱' })
  @IsOptional()
  @prop()
  email: string;

  @ApiProperty({ description: '状态（正常、停用）' })
  @IsNotEmpty({ message: '状态不能为空' })
  @prop()
  status: string;

  @ApiProperty({ description: '角色, 可选择多个' })
  @IsNotEmpty({ message: '角色不能为空' })
  @prop()
  roles: any[];

  @Allow()
  _id: string;

  @Allow()
  createdAt: string;

  @Allow()
  updatedAt: string;

  @Allow()
  __v: string;
}
